package com.culturalCenter.dataCenter.service.impl.user;

import com.culturalCenter.dataCenter.Utils.MapperUtil;
import com.culturalCenter.dataCenter.customEntity.user.CustomActivityStatistics;
import com.culturalCenter.dataCenter.entity.user.UserActivityCount;
import com.culturalCenter.dataCenter.mapper.user.UserActivityCountMapper;
import com.culturalCenter.dataCenter.mapper.user.UserActivitySignUpContentTypeMapper;
import com.culturalCenter.dataCenter.mapper.user.UserActivitySignUpTypeMapper;
import com.culturalCenter.dataCenter.service.user.UserActivityCountService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/****
 * @Author:
 * @Description:UserActivityCount业务层接口实现类
 * @Date
 *****/
@Service
public class UserActivityCountServiceImpl implements UserActivityCountService {

    @Resource
    private UserActivityCountMapper userActivityCountMapper;
    @Resource
    private UserActivitySignUpTypeMapper userActivitySignUpTypeMapper;
    @Resource
    private UserActivitySignUpContentTypeMapper userActivitySignUpContentTypeMapper;
    @Resource
    private MapperUtil mapperUtil;

    @Override
    public PageInfo<UserActivityCount> findPage(int page, int size) {
        return PageHelper.startPage(page, size).doSelectPageInfo(() -> userActivityCountMapper.findPageAll());
    }

    @Override
    public Integer delete(String id) {
        return userActivityCountMapper.deleteById(id);
    }

    @Override
    public Integer update(UserActivityCount userActivityCount) {
        return userActivityCountMapper.update(userActivityCount);
    }

    @Override
    public Integer add(UserActivityCount userActivityCount) {
        return userActivityCountMapper.insert(userActivityCount);
    }

    @Override
    public UserActivityCount findById(String id) {
        return userActivityCountMapper.queryById(id);
    }

    @Override
    public List<UserActivityCount> findAll(UserActivityCount userActivityCount) {
        return (List<UserActivityCount>) userActivityCountMapper.queryAll(userActivityCount);
    }

    @Override
    public CustomActivityStatistics findByUserIdAndType(String userId) {
        CustomActivityStatistics customActivityStatistics = new CustomActivityStatistics();
        UserActivityCount userActivityCount = (UserActivityCount) mapperUtil.getOneResult(userActivityCountMapper, userId);
        if (userActivityCount != null) {
            BeanUtils.copyProperties(userActivityCount, customActivityStatistics);
        }
        customActivityStatistics.setActivityTypeList(userActivitySignUpTypeMapper.queryByUserId(userId));
        customActivityStatistics.setActivityContentList(userActivitySignUpContentTypeMapper.queryByUserId(userId));
        return customActivityStatistics;
    }

}
